<?php
/**
 * Albireo Kernel
 *
 * @copyright  Copyright (c) 2010 Albireo Solutions
 * @package    Kernel
 */
namespace Celebrio\Util;

use Nette\Object;
use Nette\Environment;

abstract class DateParser extends Object {
    
    public static function get_date($date_to_parse, $language = null) {
        if (is_null($language)) {
            $language = Environment::getUser()->getIdentity()->language;
        }
        
        if($language === "cs_CZ" || $language === "sk_SK") {
            $format = "j. n. Y";
        } else if($language === "en_US") {
            $format = "m/d/Y";
        } else {
            $format = "j. n. Y";
        }
        
        $date = date($format, strtotime($date_to_parse));

        return $date;
    }
    
    public static function getFullDate(\DateTime $date_to_parse, $language = null) {
        if (is_null($language)) {
            $language = Environment::getUser()->getIdentity()->language;
        }
        
        if($language === "cs_CZ" || $language === "sk_SK") {
            $format = "j. n. Y H:i:s";
        } else if($language === "en_US") {
            $format = "m/d/Y H:i:s";
        } else {
            $format = "j. n. Y H:i:s" ;
        }
        return $date_to_parse->format($format);
    }
    
    /**
     *
     * @param type $date
     * @param type $alternative specifies if user want to see alternative names
     * of the day (today, tomorrow)
     * @return type String translated name of day
     */
    public static function getDayOfWeek($date, $alternative = false) {
        
        if($alternative) {
            $today = date("Y-m-d");
            $date_c = new \DateTime($date);
            $today_c = new \DateTime($today);
            $interval = $date_c->diff($today_c, false);
            //For checking if it is a day before simply check d = 1 and invert = 0
            if($interval->d === 0) {
                $day = _("Today");
            } else if(($interval->d === 1) && ($interval->invert === 1)) {
                $day = _("Tomorrow");
            } else {
                $day_number = \date("w", strtotime($date));
                $days = array(
                    0 => _("Sunday"),
                    1 => _("Monday"),
                    2 => _("Tuesday"),
                    3 => _("Wednesday"),
                    4 => _("Thursday"),
                    5 => _("Friday"),
                    6 => _("Saturday")
                );
                
                $day = $days[$day_number];
            }
        }
        
        return $day;
    }
    
}

?>
